
/**
 * Card object of a deck of cards
 * 
 * @author James Knight
 * @author Cheri Kau
 */
public class Card implements Comparable<Card> 
{
	public static final int NULL = 0;
	public static final int CLUBS = 1;
	public static final int SPADES = 2;
	public static final int HEARTS = 3;
	public static final int DIAMONDS = 4;

	// define the face cards
	public static final int ACE = 5;
	public static final int KING = 6;
	public static final int QUEEN = 7;
	public static final int JACK = 8;

	private int cardvalue = 0;
	private int cardsuit = 0;

	/**
	 * Constructs a new card with the given face value and suit.
	 * 
	 * @param value - value of card
	 * @param suit - value of suit
	 * 
	 */

	public Card(int value, int suit) 
	{
		cardvalue = value;
		cardsuit = suit;
	}

	/**
	 * Returns the face value of this card. If not between 1 thru 13, return
	 * null.
	 */

	public int getRank() 
	{
		if (cardvalue >= 1 && cardvalue <= 10) 
		{
			return cardvalue;
		} 
		else if (cardvalue >= 11 && cardvalue <= 13) 
		{
			return 10;
		} 
		else 
		{
			return NULL;
		}
	}

	/**
	 * @return the suit of this card
	 */

	public int getSuit() 
	{
		return cardsuit;
	}

	/**
	 * Compare method used for sorting.
	 * 
	 * @param Card card - card to compare
	 */

	public int compareTo(Card card) 
	{
		if ((this.getRank() == 1) && (card.getRank() == 1)) 
		{
			return 0;
		} 
		else if (this.getRank() == 1) 
		{
			return 1;
		} 
		else if (card.getRank() == 1) 
		{
			return -1;
		} 
		else if (this.getRank() < card.getRank()) 
		{
			return -1;
		} 
		else if (this.getRank() == card.getRank()) 
		{
			return 0;
		} 
		else 
		{
			return 1;
		}
	}

	/**
	 * Returns current card value.
	 */

	public int getCardValue() 
	{
		return cardvalue;
	}

	/**
	 * Returns string representation of suit/rank.
	 * 
	 */

	public String toString() 
	{
		String value = "";
		String suit = "";

		if ((cardvalue >= 1 && cardvalue <= 13)
				&& (cardsuit >= 1 && cardsuit <= 4)) 
		{
			if ((cardvalue >= 2 && cardvalue <= 10)) 
			{
				value = "" + cardvalue;
			}

			else 
			{
				if (cardvalue == 1) 
				{
					value = "Ace";
				} 
				else if (cardvalue == 11) 
				{
					value = "Jack";
				} 
				else if (cardvalue == 12) 
				{
					value = "Queen";
				} 
				else if (cardvalue == 13) 
				{
					value = "King";
				}

			}

			if (cardsuit == 1) 
			{
				suit = "Clubs";
			} 
			else if (cardsuit == 2) 
			{
				suit = "Spades";
			} 
			else if (cardsuit == 3) 
			{
				suit = "Hearts";
			} 
			else if (cardsuit == 4) 
			{
				suit = "Diamonds";
			}

			return value + " of " + suit;

		} 
		else 
		{
			return "ERROR";
		}
	}
}